// 禁止回退
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
    history.pushState(null, null, document.URL);
});

// 检测回车事件
document.onkeydown = function (key) {
    if (key.keyCode === 13) {
        login();
    }
}

// 检测用户名是否存在
function login() {
    let userName = document.getElementById("userName").value;
    let userPass = document.getElementById("userPass").value;
    if (userName == "") {
        alert("请输入您的用户名！");
    } else if (userPass == "") {
        alert("请输入您的密码！");
    } else {
        axios.post("//81.69.27.130/product/login?password=" + userPass + "&username=" + userName)
            .then(function (response) {
                console.log(response.data.msg);
                if(response.data.msg == "登陆失败"){
                    alert("账号秘密错误，请重试！");
                    location.reload();
                }else{
                location.href = 'index.html?' + 'user=' + encodeURI(userName);
                }
                // if(response.data.msg){

                // }
                // location.href = 'index.html?' + 'user=' + encodeURI(userName);
            }, function (err) {})
    }
}